<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH . 'models/m_select.php';

/**
 * Модель выборки комментариев
 *
 * @package CoreFramework
 * @version 1.0
 * @author Gennadiy Kozlenko
 */
class M_Select_Comments extends M_Select {
   
   /**
    * Конструктор класса
    *
    * @access public
    * @return M_Select_Comments
    */
   function M_Select_Comments() {
      parent::M_Select();
      $this->load->language('select_comments');
   } // end M_Select_Comments
   
   /**
    * Инициализация модельки
    *
    */
   function initialize() {
      // Устанавливаем запрос
      $sql = "
         SELECT
            vc.id_comment AS id,
            v.title,
            v.orig_title AS orig_title_hidden,
            v.year AS year_hidden,
            vc.author,
            vc.email AS email_hidden,
            vc.date_created,
            vc.comment,
            vc.status
         FROM
            " . $this->db->dbprefix('video_comments') . " vc
               LEFT JOIN " . $this->db->dbprefix('videos') . " v ON (v.id_video = vc.id_video AND v.status <> 'deleted')
         WHERE
            vc.status <> 'deleted'
      ";
      parent::set_sql($sql);
   }
   
   /**
    * Обработка результата
    *
    * @access protected
    * @param array $result
    */
   function _process_result(&$result) {
      if (!empty($result['orig_title_hidden'])) {
         $result['title'] .= ' / ' . $result['orig_title_hidden'];
      }
      if (!empty($result['year_hidden'])) {
         $result['title'] .= ' (' . $result['year_hidden'] . ')';
      }
      if (!empty($result['email_hidden'])) {
         $result['author'] .= '<br /><a href="mailto:' . $result['email_hidden'] . '">' . $result['email_hidden'] . '</a>';
      }
      $result['comment'] = nl2br(htmlspecialchars($result['comment']));
   } // end _process_result
   
}
